<?php
namespace Api\Controller;
use Think\Controller;
class NotifyController extends Controller {
    public function index(){
        $xmlObj = simplexml_load_string($GLOBALS['HTTP_RAW_POST_DATA']); //解析回调数据
        $appid = (string)$xmlObj->appid;//微信appid
        $mch_id = (string)$xmlObj->mch_id;  //商户号
        $nonce_str = (string)$xmlObj->nonce_str;//随机字符串
        $sign = (string)$xmlObj->sign;//签名
        $result_code = (string)$xmlObj->result_code;//业务结果
        $openid = (string)$xmlObj->openid;//用户标识
        $is_subscribe = (string)$xmlObj->is_subscribe;//是否关注公众帐号
        $trace_type = (string)$xmlObj->trade_type;//交易类型，JSAPI,NATIVE,APP
        $bank_type = (string)$xmlObj->bank_type;//付款银行，银行类型采用字符串类型的银行标识。
        $total_fee = (string)$xmlObj->total_fee;//订单总金额，单位为分
        $fee_type = (string)$xmlObj->fee_type;//货币类型，符合ISO4217的标准三位字母代码，默认为人民币：CNY。
        $transaction_id = (string)$xmlObj->transaction_id;//微信支付订单号
        $out_trade_no = (string)$xmlObj->out_trade_no;//商户订单号
        $attach = (string)$xmlObj->attach;//商家数据包，原样返回
        $time_end = (string)$xmlObj->time_end;//支付完成时间
        $cash_fee = (string)$xmlObj->cash_fee;
        $return_code = (string)$xmlObj->return_code;

        $map['out_trade_no'] = $out_trade_no;
        $data['transaction_id'] = $transaction_id;
        // $data['isPay'] = 1;
        $type = $_GET['type'];
        echo "success";
    }
    public function renewShop(){
        $xmlObj = simplexml_load_string($GLOBALS['HTTP_RAW_POST_DATA']); //解析回调数据
        $appid = (string)$xmlObj->appid;//微信appid
        $mch_id = (string)$xmlObj->mch_id;  //商户号
        $nonce_str = (string)$xmlObj->nonce_str;//随机字符串
        $sign = (string)$xmlObj->sign;//签名
        $result_code = (string)$xmlObj->result_code;//业务结果
        $openid = (string)$xmlObj->openid;//用户标识
        $is_subscribe = (string)$xmlObj->is_subscribe;//是否关注公众帐号
        $trace_type = (string)$xmlObj->trade_type;//交易类型，JSAPI,NATIVE,APP
        $bank_type = (string)$xmlObj->bank_type;//付款银行，银行类型采用字符串类型的银行标识。
        $total_fee = (string)$xmlObj->total_fee;//订单总金额，单位为分
        $fee_type = (string)$xmlObj->fee_type;//货币类型，符合ISO4217的标准三位字母代码，默认为人民币：CNY。
        $transaction_id = (string)$xmlObj->transaction_id;//微信支付订单号
        $out_trade_no = (string)$xmlObj->out_trade_no;//商户订单号
        $attach = (string)$xmlObj->attach;//商家数据包，原样返回
        $time_end = (string)$xmlObj->time_end;//支付完成时间
        $cash_fee = (string)$xmlObj->cash_fee;
        $return_code = (string)$xmlObj->return_code;

        $map['out_trade_no'] = $out_trade_no;
        $data['transaction_id'] = $transaction_id;

        $data['pay_time'] = date("Y-m-d H:i:s",strtotime($time_end));
        $data['is_pay'] = 1;
        M("ShopOrder")->where($map)->save($data);

        $info = M("ShopOrder")->where($map)->find();
        $eq['shop_id'] = $info['shop_id'];
        $new['is_pay'] = 1;
        $new['status'] = 1;
        $new['join_end_time'] = date("Y-m-d H:i:s", strtotime("+ {$info['join_days']}days"));
        M("Shop")->where($eq)->save($new);
    }
    public function reserveOrder(){
        $xmlObj = simplexml_load_string($GLOBALS['HTTP_RAW_POST_DATA']); //解析回调数据
        $appid = (string)$xmlObj->appid;//微信appid
        $mch_id = (string)$xmlObj->mch_id;  //商户号
        $nonce_str = (string)$xmlObj->nonce_str;//随机字符串
        $sign = (string)$xmlObj->sign;//签名
        $result_code = (string)$xmlObj->result_code;//业务结果
        $openid = (string)$xmlObj->openid;//用户标识
        $is_subscribe = (string)$xmlObj->is_subscribe;//是否关注公众帐号
        $trace_type = (string)$xmlObj->trade_type;//交易类型，JSAPI,NATIVE,APP
        $bank_type = (string)$xmlObj->bank_type;//付款银行，银行类型采用字符串类型的银行标识。
        $total_fee = (string)$xmlObj->total_fee;//订单总金额，单位为分
        $fee_type = (string)$xmlObj->fee_type;//货币类型，符合ISO4217的标准三位字母代码，默认为人民币：CNY。
        $transaction_id = (string)$xmlObj->transaction_id;//微信支付订单号
        $out_trade_no = (string)$xmlObj->out_trade_no;//商户订单号
        $attach = (string)$xmlObj->attach;//商家数据包，原样返回
        $time_end = (string)$xmlObj->time_end;//支付完成时间
        $cash_fee = (string)$xmlObj->cash_fee;
        $return_code = (string)$xmlObj->return_code;

        $data = array();
        $data['is_pay'] = 1;
        $data['pay_time'] = date("Y-m-d H:i:s",strtotime($time_end));
        $data['state'] = 1;
        M('takeout_ydorder')->where(array('ydcode'=>$out_trade_no))->save($data);

    }
    public function takeoutOrder(){
        $xmlObj = simplexml_load_string($GLOBALS['HTTP_RAW_POST_DATA']); //解析回调数据
        $appid = (string)$xmlObj->appid;//微信appid
        $mch_id = (string)$xmlObj->mch_id;  //商户号
        $nonce_str = (string)$xmlObj->nonce_str;//随机字符串
        $sign = (string)$xmlObj->sign;//签名
        $result_code = (string)$xmlObj->result_code;//业务结果
        $openid = (string)$xmlObj->openid;//用户标识
        $is_subscribe = (string)$xmlObj->is_subscribe;//是否关注公众帐号
        $trace_type = (string)$xmlObj->trade_type;//交易类型，JSAPI,NATIVE,APP
        $bank_type = (string)$xmlObj->bank_type;//付款银行，银行类型采用字符串类型的银行标识。
        $total_fee = (string)$xmlObj->total_fee;//订单总金额，单位为分
        $fee_type = (string)$xmlObj->fee_type;//货币类型，符合ISO4217的标准三位字母代码，默认为人民币：CNY。
        $transaction_id = (string)$xmlObj->transaction_id;//微信支付订单号
        $out_trade_no = (string)$xmlObj->out_trade_no;//商户订单号
        $attach = (string)$xmlObj->attach;//商家数据包，原样返回
        $time_end = (string)$xmlObj->time_end;//支付完成时间
        $cash_fee = (string)$xmlObj->cash_fee;
        $return_code = (string)$xmlObj->return_code;

        $data = array();
        $data['is_pay'] = 1;
        $data['state'] = 2;
        $data['pay_time'] = date("Y-m-d H:i:s",strtotime($time_end));
        M('takeout_order')->where(array('sh_ordernum'=>$out_trade_no))->save($data);

    }
}